package com.waiting.webServiceClient;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/1/22
 **/
public class Main {
    public static void main(String[] args) {
        JaxWsDynamicClientFactory dcflient = JaxWsDynamicClientFactory.newInstance();

        Client client = dcflient.createClient("http://localhost:8080/webservice/myWebService?wsdl");

        Object[] objects = new Object[0];
        try {
            objects = client.invoke("getname", "");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("*******" + objects[0].toString());

        Object[] objectall = new Object[0];
        try {
            objectall = client.invoke("twoParm", "waiting", "test");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("*******" + objectall[0].toString());
    }
//
//    //调用方式二，通过接口协议获取数据类型
//    public static void main2(String[] args) throws Exception {
//        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
//        jaxWsProxyFactoryBean.setAddress("http://localhost:8080/service/user?wsdl");
//        jaxWsProxyFactoryBean.setServiceClass(UserService.class);
//
//        UserService userService = (UserService) jaxWsProxyFactoryBean.create();
//        User userResult = userService.getUser("411001");
//        System.out.println("UserName:" + userResult.getUsername());
//        ArrayList<User> users = userService.getAlLUser();
//
//    }
//
//
//    //调用方式三，通过接口协议获取数据类型,设置链接超时和响应时间
//    public static void main3(String[] args) throws Exception {
//        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
//        jaxWsProxyFactoryBean.setAddress("http://localhost:8080/service/user?wsdl");
//        jaxWsProxyFactoryBean.setServiceClass(UserService.class);
//
//        UserService userService = (UserService) jaxWsProxyFactoryBean.create(); // 创建客户端对象
//        Client proxy = ClientProxy.getClient(userService);
//        HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
//        HTTPClientPolicy policy = new HTTPClientPolicy();
//        policy.setConnectionTimeout(1000);
//        policy.setReceiveTimeout(1000);
//        conduit.setClient(policy);
//
//        User userResult = userService.getUser("411001");
//        System.out.println("UserName:" + userResult.getUsername());
//        ArrayList<User> users = userService.getAlLUser();
//
//    }
}
